# -*- coding: UTF-8 -*-
"""
@Project ：zzytgitee
@File ：test.py
@Author ：正途皆是道
@Date ：21-6-18 下午5:18
"""
import csv
import os
csv_dir = '/media/chan/软件/LTLDataset/豆瓣影评/reviews'
text_dir = '/media/chan/软件/LTLDataset/豆瓣影评/txt/'
if not os.path.exists(text_dir):
    os.mkdir(text_dir)

def csv2txt():
    csv_names = os.listdir(csv_dir)
    for csv_name in csv_names:
        csv_path = os.path.join(csv_dir, csv_name)
        txt_path = os.path.join(text_dir, csv_name.replace('.csv', '.txt'))
        if 'csv' not in csv_name:
            continue
        print(csv_name)
        with open(csv_path, encoding='utf-8-sig') as f:
            reader = csv.reader(f)
            next(reader)
            for i, row in enumerate(reader):
                chapter_name = '第' + str(i) + '章：' + row[0] + '-' + row[2] + '-赞：' + row[3] + '-恶：' + row[4]
                data = row[-1]
                with open(txt_path, 'a+') as train_label_f:
                    train_label_f.write(chapter_name + '\r\n' + data + '\r\n')


if __name__ == '__main__':
    csv2txt()
